package ru.urfc.portal.developer_tasks.ejb_tests;

import javax.ejb.EJB;

import ru.urfc.portal.dao.SpectrId;
import ru.urfc.portal.developer_tasks.BaseTestEjb;
import ru.urfc.portal.developer_tasks.Initializer;
import ru.urfc.portal.managers.NetManager;
import ru.urfc.portal.model.Client;
import ru.urfc.portal.model.Branch;
import ru.urfc.portal.model.accounting.Contragent;
import ru.urfc.portal.model.radio.NetLicense;
import ru.urfc.portal.model.radio.NetWithLicense;

public class NetManagerTestEjb extends BaseTestEjb {

	@EJB NetManager netManager;

	Client client;
	Client client2;
	NetWithLicense net;
	NetWithLicense net2;
	NetLicense netLicense;
	
	@Override
	protected void setUp() throws Exception {
		client = findClient(Initializer.CONTRAGENT_NAME_MTS);
		client2 = findClient(Initializer.CONTRAGENT_NAME_QQ);
		netLicense = exactlyOne(find(Branch.SVERD, NetLicense.class, "number", Initializer.CLIENT_MTS_NET_LICENSE_NUMBER));
		net = netLicense.getNet();
		Contragent contragent2 = findById(Contragent.class, new SpectrId(client));
		net2 = persist(new NetWithLicense(contragent2));
	}
	
	public void testGetNetException() {
		netManager.getNetWithLicense(client.getId(), net.getId());
		setExpectedUserGetItemException();
		netManager.getNetWithLicense(client2.getId(), net.getId());
	}
	
	public void testGetNetChannelsException() {
		netManager.getNetChannels(client.getId(), net.getId());
		setExpectedUserGetItemException();
		netManager.getNetChannels(client2.getId(), net.getId());
	}
	
	public void testGetNetDevicesException() {
		netManager.getNetDevices(client.getId(), net.getId());
		setExpectedUserGetItemException();
		netManager.getNetDevices(client2.getId(), net.getId());
	}	
	
	public void testGetNetLicensesException() {
		netManager.getNetLicenses(client.getId(), net.getId());
		setExpectedUserGetItemException();
		netManager.getNetLicenses(client2.getId(), net.getId());
	}	
	
	public void testGetNetLicenseExceptionWrongClient() {
		netManager.getNetLicense(client.getId(), net.getId(), netLicense.getId());
		setExpectedUserGetItemException();
		netManager.getNetLicense(client2.getId(), net.getId(), netLicense.getId());
	}	
	
	public void testGetNetLicenseExceptionWrongNet() {
		netManager.getNetLicense(client.getId(), net.getId(), netLicense.getId());
		setExpectedUserGetItemException();
		netManager.getNetLicense(client.getId(), net2.getId(), netLicense.getId());
	}	
	
	public void testGetNetLicenseExceptionAnotherClientAndNet() {
		netManager.getNetLicense(client.getId(), net.getId(), netLicense.getId());
		setExpectedUserGetItemException();
		netManager.getNetLicense(client2.getId(), net2.getId(), netLicense.getId());
	}	
	
	

}
